#!/usr/bin/perl
####################################################################
#
#    This file was generated using Parse::Yapp version 1.05.
#
#        Don't edit this file, use source file instead.
#
#             ANY CHANGE MADE HERE WILL BE LOST !
#
####################################################################
package lemon2yapp;
use vars qw ( @ISA );
use strict;

@ISA= qw ( Parse::Yapp::Driver );
#Included Parse/Yapp/Driver.pm file----------------------------------------
{
#
# Module Parse::Yapp::Driver
#
# This module is part of the Parse::Yapp package available on your
# nearest CPAN
#
# Any use of this module in a standalone parser make the included
# text under the same copyright as the Parse::Yapp module itself.
#
# This notice should remain unchanged.
#
# (c) Copyright 1998-2001 Francois Desarmenien, all rights reserved.
# (see the pod text in Parse::Yapp module for use and distribution rights)
#

package Parse::Yapp::Driver;

require 5.004;

use strict;

use vars qw ( $VERSION $COMPATIBLE $FILENAME );

$VERSION = '1.05';
$COMPATIBLE = '0.07';
$FILENAME=__FILE__;

use Carp;

#Known parameters, all starting with YY (leading YY will be discarded)
my(%params)=(YYLEX => 'CODE', 'YYERROR' => 'CODE', YYVERSION => '',
			 YYRULES => 'ARRAY', YYSTATES => 'ARRAY', YYDEBUG => '');
#Mandatory parameters
my(@params)=('LEX','RULES','STATES');

sub new {
    my($class)=shift;
	my($errst,$nberr,$token,$value,$check,$dotpos);
    my($self)={ ERROR => \&_Error,
				ERRST => \$errst,
                NBERR => \$nberr,
				TOKEN => \$token,
				VALUE => \$value,
				DOTPOS => \$dotpos,
				STACK => [],
				DEBUG => 0,
				CHECK => \$check };

	_CheckParams( [], \%params, \@_, $self );

		exists($$self{VERSION})
	and	$$self{VERSION} < $COMPATIBLE
	and	croak "Yapp driver version $VERSION ".
			  "incompatible with version $$self{VERSION}:\n".
			  "Please recompile parser module.";

        ref($class)
    and $class=ref($class);

    bless($self,$class);
}

sub YYParse {
    my($self)=shift;
    my($retval);

	_CheckParams( \@params, \%params, \@_, $self );

	if($$self{DEBUG}) {
		_DBLoad();
		$retval = eval '$self->_DBParse()';#Do not create stab entry on compile
        $@ and die $@;
	}
	else {
		$retval = $self->_Parse();
	}
    $retval
}

sub YYData {
	my($self)=shift;

		exists($$self{USER})
	or	$$self{USER}={};

	$$self{USER};
	
}

sub YYErrok {
	my($self)=shift;

	${$$self{ERRST}}=0;
    undef;
}

sub YYNberr {
	my($self)=shift;

	${$$self{NBERR}};
}

sub YYRecovering {
	my($self)=shift;

	${$$self{ERRST}} != 0;
}

sub YYAbort {
	my($self)=shift;

	${$$self{CHECK}}='ABORT';
    undef;
}

sub YYAccept {
	my($self)=shift;

	${$$self{CHECK}}='ACCEPT';
    undef;
}

sub YYError {
	my($self)=shift;

	${$$self{CHECK}}='ERROR';
    undef;
}

sub YYSemval {
	my($self)=shift;
	my($index)= $_[0] - ${$$self{DOTPOS}} - 1;

		$index < 0
	and	-$index <= @{$$self{STACK}}
	and	return $$self{STACK}[$index][1];

	undef;	#Invalid index
}

sub YYCurtok {
	my($self)=shift;

        @_
    and ${$$self{TOKEN}}=$_[0];
    ${$$self{TOKEN}};
}

sub YYCurval {
	my($self)=shift;

        @_
    and ${$$self{VALUE}}=$_[0];
    ${$$self{VALUE}};
}

sub YYExpect {
    my($self)=shift;

    keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}}
}

sub YYLexer {
    my($self)=shift;

	$$self{LEX};
}


#################
# Private stuff #
#################


sub _CheckParams {
	my($mandatory,$checklist,$inarray,$outhash)=@_;
	my($prm,$value);
	my($prmlst)={};

	while(($prm,$value)=splice(@$inarray,0,2)) {
        $prm=uc($prm);
			exists($$checklist{$prm})
		or	croak("Unknow parameter '$prm'");
			ref($value) eq $$checklist{$prm}
		or	croak("Invalid value for parameter '$prm'");
        $prm=unpack('@2A*',$prm);
		$$outhash{$prm}=$value;
	}
	for (@$mandatory) {
			exists($$outhash{$_})
		or	croak("Missing mandatory parameter '".lc($_)."'");
	}
}

sub _Error {
	print "Parse error.\n";
}

sub _DBLoad {
	{
		no strict 'refs';

			exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ?
		and	return;
	}
	my($fname)=__FILE__;
	my(@drv);
	open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname";
	while(<DRV>) {
                	/^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/
        	and     do {
                	s/^#DBG>//;
                	push(@drv,$_);
        	}
	}
	close(DRV);

	$drv[0]=~s/_P/_DBP/;
	eval join('',@drv);
}

#Note that for loading debugging version of the driver,
#this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive.
#So, DO NOT remove comment at end of sub !!!
sub _Parse {
    my($self)=shift;

	my($rules,$states,$lex,$error)
     = @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' };
	my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos)
     = @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' };

#DBG>	my($debug)=$$self{DEBUG};
#DBG>	my($dbgerror)=0;

#DBG>	my($ShowCurToken) = sub {
#DBG>		my($tok)='>';
#DBG>		for (split('',$$token)) {
#DBG>			$tok.=		(ord($_) < 32 or ord($_) > 126)
#DBG>					?	sprintf('<%02X>',ord($_))
#DBG>					:	$_;
#DBG>		}
#DBG>		$tok.='<';
#DBG>	};

	$$errstatus=0;
	$$nberror=0;
	($$token,$$value)=(undef,undef);
	@$stack=( [ 0, undef ] );
	$$check='';

    while(1) {
        my($actions,$act,$stateno);

        $stateno=$$stack[-1][0];
        $actions=$$states[$stateno];

#DBG>	print STDERR ('-' x 40),"\n";
#DBG>		$debug & 0x2
#DBG>	and	print STDERR "In state $stateno:\n";
#DBG>		$debug & 0x08
#DBG>	and	print STDERR "Stack:[".
#DBG>					 join(',',map { $$_[0] } @$stack).
#DBG>					 "]\n";


        if  (exists($$actions{ACTIONS})) {

				defined($$token)
            or	do {
				($$token,$$value)=&$lex($self);
#DBG>				$debug & 0x01
#DBG>			and	print STDERR "Need token. Got ".&$ShowCurToken."\n";
			};

            $act=   exists($$actions{ACTIONS}{$$token})
                    ?   $$actions{ACTIONS}{$$token}
                    :   exists($$actions{DEFAULT})
                        ?   $$actions{DEFAULT}
                        :   undef;
        }
        else {
            $act=$$actions{DEFAULT};
#DBG>			$debug & 0x01
#DBG>		and	print STDERR "Don't need token.\n";
        }

            defined($act)
        and do {

                $act > 0
            and do {        #shift

#DBG>				$debug & 0x04
#DBG>			and	print STDERR "Shift and go to state $act.\n";

					$$errstatus
				and	do {
					--$$errstatus;

#DBG>					$debug & 0x10
#DBG>				and	$dbgerror
#DBG>				and	$$errstatus == 0
#DBG>				and	do {
#DBG>					print STDERR "**End of Error recovery.\n";
#DBG>					$dbgerror=0;
#DBG>				};
				};


                push(@$stack,[ $act, $$value ]);

					$$token ne ''	#Don't eat the eof
				and	$$token=$$value=undef;
                next;
            };

            #reduce
            my($lhs,$len,$code,@sempar,$semval);
            ($lhs,$len,$code)=@{$$rules[-$act]};

#DBG>			$debug & 0x04
#DBG>		and	$act
#DBG>		and	print STDERR "Reduce using rule ".-$act." ($lhs,$len): ";

                $act
            or  $self->YYAccept();

            $$dotpos=$len;

                unpack('A1',$lhs) eq '@'    #In line rule
            and do {
                    $lhs =~ /^\@[0-9]+\-([0-9]+)$/
                or  die "In line rule name '$lhs' ill formed: ".
                        "report it as a BUG.\n";
                $$dotpos = $1;
            };

            @sempar =       $$dotpos
                        ?   map { $$_[1] } @$stack[ -$$dotpos .. -1 ]
                        :   ();

            $semval = $code ? &$code( $self, @sempar )
                            : @sempar ? $sempar[0] : undef;

            splice(@$stack,-$len,$len);

                $$check eq 'ACCEPT'
            and do {

#DBG>			$debug & 0x04
#DBG>		and	print STDERR "Accept.\n";

				return($semval);
			};

                $$check eq 'ABORT'
            and	do {

#DBG>			$debug & 0x04
#DBG>		and	print STDERR "Abort.\n";

				return(undef);

			};

#DBG>			$debug & 0x04
#DBG>		and	print STDERR "Back to state $$stack[-1][0], then ";

                $$check eq 'ERROR'
            or  do {
#DBG>				$debug & 0x04
#DBG>			and	print STDERR 
#DBG>				    "go to state $$states[$$stack[-1][0]]{GOTOS}{$lhs}.\n";

#DBG>				$debug & 0x10
#DBG>			and	$dbgerror
#DBG>			and	$$errstatus == 0
#DBG>			and	do {
#DBG>				print STDERR "**End of Error recovery.\n";
#DBG>				$dbgerror=0;
#DBG>			};

			    push(@$stack,
                     [ $$states[$$stack[-1][0]]{GOTOS}{$lhs}, $semval ]);
                $$check='';
                next;
            };

#DBG>			$debug & 0x04
#DBG>		and	print STDERR "Forced Error recovery.\n";

            $$check='';

        };

        #Error
            $$errstatus
        or   do {

            $$errstatus = 1;
            &$error($self);
                $$errstatus # if 0, then YYErrok has been called
            or  next;       # so continue parsing

#DBG>			$debug & 0x10
#DBG>		and	do {
#DBG>			print STDERR "**Entering Error recovery.\n";
#DBG>			++$dbgerror;
#DBG>		};

            ++$$nberror;

        };

			$$errstatus == 3	#The next token is not valid: discard it
		and	do {
				$$token eq ''	# End of input: no hope
			and	do {
#DBG>				$debug & 0x10
#DBG>			and	print STDERR "**At eof: aborting.\n";
				return(undef);
			};

#DBG>			$debug & 0x10
#DBG>		and	print STDERR "**Dicard invalid token ".&$ShowCurToken.".\n";

			$$token=$$value=undef;
		};

        $$errstatus=3;

		while(	  @$stack
			  and (		not exists($$states[$$stack[-1][0]]{ACTIONS})
			        or  not exists($$states[$$stack[-1][0]]{ACTIONS}{error})
					or	$$states[$$stack[-1][0]]{ACTIONS}{error} <= 0)) {

#DBG>			$debug & 0x10
#DBG>		and	print STDERR "**Pop state $$stack[-1][0].\n";

			pop(@$stack);
		}

			@$stack
		or	do {

#DBG>			$debug & 0x10
#DBG>		and	print STDERR "**No state left on stack: aborting.\n";

			return(undef);
		};

		#shift the error token

#DBG>			$debug & 0x10
#DBG>		and	print STDERR "**Shift \$error token and go to state ".
#DBG>						 $$states[$$stack[-1][0]]{ACTIONS}{error}.
#DBG>						 ".\n";

		push(@$stack, [ $$states[$$stack[-1][0]]{ACTIONS}{error}, undef ]);

    }

    #never reached
	croak("Error in driver logic. Please, report it as a BUG");

}#_Parse
#DO NOT remove comment

1;

}
#End of include--------------------------------------------------


#line 2 "lemon2yapp.yp"


#
# Copyright (c) 2007, Micha Niskin
# 
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
# 
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
# 
#   * Neither the name of the organization nor the names of its contributors
#     may be used to endorse or promote products derived from this software
#     without specific prior written permission.
# 
# 
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

  our %rule = ();
  our %seen = ();
  our @rules = ();
  our @prec = ();


sub new {
        my($class)=shift;
        ref($class)
    and $class=ref($class);

    my($self)=$class->SUPER::new( yyversion => '1.05',
                                  yystates =>
[
	{#State 0
		ACTIONS => {
			'FI' => 9,
			'WORD' => 1,
			'LCB' => 10,
			'TYPE' => 12,
			'COMMENT' => 3,
			'FALLBACK' => 13,
			'PREC' => 5,
			'IF' => 6,
			'DESTRUCTOR' => 16,
			'WILD' => 7,
			'COM_START' => 17
		},
		GOTOS => {
			'comment' => 15,
			'word' => 14,
			'code_blk' => 2,
			'defword' => 11,
			'lines' => 4,
			'line' => 8
		}
	},
	{#State 1
		DEFAULT => -43
	},
	{#State 2
		DEFAULT => -4
	},
	{#State 3
		DEFAULT => -29
	},
	{#State 4
		ACTIONS => {
			'FI' => 9,
			'' => 18,
			'WORD' => 1,
			'LCB' => 10,
			'TYPE' => 12,
			'COMMENT' => 3,
			'FALLBACK' => 13,
			'PREC' => 5,
			'IF' => 6,
			'DESTRUCTOR' => 16,
			'WILD' => 7,
			'COM_START' => 17
		},
		GOTOS => {
			'comment' => 15,
			'word' => 14,
			'code_blk' => 2,
			'defword' => 11,
			'line' => 19
		}
	},
	{#State 5
		ACTIONS => {
			'WORD' => 1
		},
		GOTOS => {
			'word' => 21,
			'words' => 20
		}
	},
	{#State 6
		ACTIONS => {
			'WORD' => 1
		},
		GOTOS => {
			'word' => 22
		}
	},
	{#State 7
		ACTIONS => {
			'WORD' => 1
		},
		GOTOS => {
			'word' => 21,
			'words' => 23
		}
	},
	{#State 8
		DEFAULT => -2
	},
	{#State 9
		DEFAULT => -11
	},
	{#State 10
		ACTIONS => {
			'EQ' => 31,
			'WORD' => 24,
			'LCB' => 10,
			'DOT' => 33,
			'RB' => 32,
			'RCB' => 26,
			'COMMENT' => 3,
			'LP' => 34,
			'LB' => 28,
			'RP' => 29,
			'COM_START' => 17
		},
		GOTOS => {
			'comment' => 35,
			'code_blk' => 25,
			'codes' => 27,
			'code' => 30
		}
	},
	{#State 11
		ACTIONS => {
			'EQ' => 36
		}
	},
	{#State 12
		ACTIONS => {
			'WORD' => 37
		}
	},
	{#State 13
		ACTIONS => {
			'FI' => 41,
			'WORD' => 1,
			'IF' => 39
		},
		GOTOS => {
			'word' => 42,
			'fbword' => 38,
			'fbwords' => 40
		}
	},
	{#State 14
		ACTIONS => {
			'EQ' => -21,
			'LP' => 43
		},
		DEFAULT => -9
	},
	{#State 15
		DEFAULT => -3
	},
	{#State 16
		ACTIONS => {
			'WORD' => 44
		}
	},
	{#State 17
		ACTIONS => {
			'EQ' => 51,
			'WORD' => 45,
			'DOT' => 54,
			'LCB' => 53,
			'RB' => 52,
			'COM_END' => 47,
			'RCB' => 46,
			'LP' => 55,
			'LB' => 48,
			'RP' => 50
		},
		GOTOS => {
			'cwords' => 56,
			'cword' => 49
		}
	},
	{#State 18
		DEFAULT => 0
	},
	{#State 19
		DEFAULT => -1
	},
	{#State 20
		ACTIONS => {
			'WORD' => 1,
			'DOT' => 57
		},
		GOTOS => {
			'word' => 58
		}
	},
	{#State 21
		DEFAULT => -42
	},
	{#State 22
		DEFAULT => -10
	},
	{#State 23
		ACTIONS => {
			'WORD' => 1,
			'DOT' => 59
		},
		GOTOS => {
			'word' => 58
		}
	},
	{#State 24
		DEFAULT => -50
	},
	{#State 25
		DEFAULT => -48
	},
	{#State 26
		DEFAULT => -44
	},
	{#State 27
		ACTIONS => {
			'EQ' => 31,
			'WORD' => 24,
			'LCB' => 10,
			'DOT' => 33,
			'RB' => 32,
			'RCB' => 60,
			'COMMENT' => 3,
			'LP' => 34,
			'LB' => 28,
			'RP' => 29,
			'COM_START' => 17
		},
		GOTOS => {
			'comment' => 35,
			'code_blk' => 25,
			'code' => 61
		}
	},
	{#State 28
		DEFAULT => -55
	},
	{#State 29
		DEFAULT => -54
	},
	{#State 30
		DEFAULT => -47
	},
	{#State 31
		DEFAULT => -51
	},
	{#State 32
		DEFAULT => -56
	},
	{#State 33
		DEFAULT => -52
	},
	{#State 34
		DEFAULT => -53
	},
	{#State 35
		DEFAULT => -49
	},
	{#State 36
		ACTIONS => {
			'WORD' => 1,
			'DOT' => 62
		},
		GOTOS => {
			'defwords' => 64,
			'word' => 65,
			'defword' => 63
		}
	},
	{#State 37
		ACTIONS => {
			'LCB' => 10
		},
		DEFAULT => -14,
		GOTOS => {
			'code_blk' => 66
		}
	},
	{#State 38
		DEFAULT => -23
	},
	{#State 39
		DEFAULT => -25
	},
	{#State 40
		ACTIONS => {
			'FI' => 41,
			'WORD' => 1,
			'DOT' => 68,
			'IF' => 39
		},
		GOTOS => {
			'word' => 42,
			'fbword' => 67
		}
	},
	{#State 41
		DEFAULT => -26
	},
	{#State 42
		DEFAULT => -24
	},
	{#State 43
		ACTIONS => {
			'WORD' => 1
		},
		GOTOS => {
			'word' => 69
		}
	},
	{#State 44
		ACTIONS => {
			'LCB' => 10
		},
		GOTOS => {
			'code_blk' => 70
		}
	},
	{#State 45
		DEFAULT => -32
	},
	{#State 46
		DEFAULT => -36
	},
	{#State 47
		DEFAULT => -27
	},
	{#State 48
		DEFAULT => -39
	},
	{#State 49
		DEFAULT => -31
	},
	{#State 50
		DEFAULT => -38
	},
	{#State 51
		DEFAULT => -33
	},
	{#State 52
		DEFAULT => -40
	},
	{#State 53
		DEFAULT => -35
	},
	{#State 54
		DEFAULT => -34
	},
	{#State 55
		DEFAULT => -37
	},
	{#State 56
		ACTIONS => {
			'EQ' => 51,
			'WORD' => 45,
			'DOT' => 54,
			'LCB' => 53,
			'RB' => 52,
			'COM_END' => 71,
			'RCB' => 46,
			'LP' => 55,
			'LB' => 48,
			'RP' => 50
		},
		GOTOS => {
			'cword' => 72
		}
	},
	{#State 57
		DEFAULT => -16
	},
	{#State 58
		DEFAULT => -41
	},
	{#State 59
		DEFAULT => -17
	},
	{#State 60
		DEFAULT => -45
	},
	{#State 61
		DEFAULT => -46
	},
	{#State 62
		ACTIONS => {
			'LB' => 73
		},
		DEFAULT => -8
	},
	{#State 63
		DEFAULT => -19
	},
	{#State 64
		ACTIONS => {
			'WORD' => 1,
			'DOT' => 74
		},
		GOTOS => {
			'word' => 65,
			'defword' => 75
		}
	},
	{#State 65
		ACTIONS => {
			'LP' => 43
		},
		DEFAULT => -21
	},
	{#State 66
		DEFAULT => -15
	},
	{#State 67
		DEFAULT => -22
	},
	{#State 68
		DEFAULT => -12
	},
	{#State 69
		ACTIONS => {
			'RP' => 76
		}
	},
	{#State 70
		DEFAULT => -13
	},
	{#State 71
		DEFAULT => -28
	},
	{#State 72
		DEFAULT => -30
	},
	{#State 73
		ACTIONS => {
			'WORD' => 1
		},
		GOTOS => {
			'word' => 77
		}
	},
	{#State 74
		ACTIONS => {
			'LB' => 78
		},
		DEFAULT => -6
	},
	{#State 75
		DEFAULT => -18
	},
	{#State 76
		DEFAULT => -20
	},
	{#State 77
		ACTIONS => {
			'RB' => 79
		}
	},
	{#State 78
		ACTIONS => {
			'WORD' => 1
		},
		GOTOS => {
			'word' => 80
		}
	},
	{#State 79
		DEFAULT => -7
	},
	{#State 80
		ACTIONS => {
			'RB' => 81
		}
	},
	{#State 81
		DEFAULT => -5
	}
],
                                  yyrules  =>
[
	[#Rule 0
		 '$start', 2, undef
	],
	[#Rule 1
		 'lines', 2, undef
	],
	[#Rule 2
		 'lines', 1, undef
	],
	[#Rule 3
		 'line', 1, undef
	],
	[#Rule 4
		 'line', 1, undef
	],
	[#Rule 5
		 'line', 7,
sub
#line 53 "lemon2yapp.yp"
{ 
      push(@rules, $_[1]->[0]) unless $seen{$_[1]->[0]}++;
      $rule{$_[1]->[0]} ||= [];
      foreach my $i (@{$_[3]}) {
        push(@{$rule{$_[1]->[0]}}, $i.' %prec '.$_[6]);
      }
    }
	],
	[#Rule 6
		 'line', 4,
sub
#line 60 "lemon2yapp.yp"
{ 
      push(@rules, $_[1]->[0]) unless $seen{$_[1]->[0]}++;
      $rule{$_[1]->[0]} ||= [];
      foreach my $i (@{$_[3]}) {
        push(@{$rule{$_[1]->[0]}}, $i);
      }
    }
	],
	[#Rule 7
		 'line', 6,
sub
#line 67 "lemon2yapp.yp"
{
      push(@rules, $_[1]->[0]) unless $seen{$_[1]->[0]}++;
      $rule{$_[1]->[0]} ||= [];
      push(@{$rule{$_[1]->[0]}}, '#empty %prec '.$_[5]);
    }
	],
	[#Rule 8
		 'line', 3,
sub
#line 72 "lemon2yapp.yp"
{
      push(@rules, $_[1]->[0]) unless $seen{$_[1]->[0]}++;
      $rule{$_[1]->[0]} ||= [];
      push(@{$rule{$_[1]->[0]}}, "#empty");
    }
	],
	[#Rule 9
		 'line', 1, undef
	],
	[#Rule 10
		 'line', 2, undef
	],
	[#Rule 11
		 'line', 1, undef
	],
	[#Rule 12
		 'line', 3, undef
	],
	[#Rule 13
		 'line', 3, undef
	],
	[#Rule 14
		 'line', 2, undef
	],
	[#Rule 15
		 'line', 3, undef
	],
	[#Rule 16
		 'line', 3,
sub
#line 84 "lemon2yapp.yp"
{push(@prec, "$_[1] $_[2]");}
	],
	[#Rule 17
		 'line', 3, undef
	],
	[#Rule 18
		 'defwords', 2,
sub
#line 88 "lemon2yapp.yp"
{
      my @ret = ();
      foreach my $i (@{$_[2]}) {
        foreach my $j (@{$_[1]}) {
          push(@ret, "$j $i");
        }
      }
      return \@ret;
    }
	],
	[#Rule 19
		 'defwords', 1, undef
	],
	[#Rule 20
		 'defword', 4,
sub
#line 100 "lemon2yapp.yp"
{
      my @t = split(/[|]/, $_[1]);
      return \@t;
    }
	],
	[#Rule 21
		 'defword', 1,
sub
#line 104 "lemon2yapp.yp"
{
      my @t = split(/[|]/, $_[1]);
      return \@t;
    }
	],
	[#Rule 22
		 'fbwords', 2,
sub
#line 110 "lemon2yapp.yp"
{return "$_[1] $_[2]";}
	],
	[#Rule 23
		 'fbwords', 1, undef
	],
	[#Rule 24
		 'fbword', 1, undef
	],
	[#Rule 25
		 'fbword', 1, undef
	],
	[#Rule 26
		 'fbword', 1, undef
	],
	[#Rule 27
		 'comment', 2, undef
	],
	[#Rule 28
		 'comment', 3, undef
	],
	[#Rule 29
		 'comment', 1, undef
	],
	[#Rule 30
		 'cwords', 2, undef
	],
	[#Rule 31
		 'cwords', 1, undef
	],
	[#Rule 32
		 'cword', 1, undef
	],
	[#Rule 33
		 'cword', 1, undef
	],
	[#Rule 34
		 'cword', 1, undef
	],
	[#Rule 35
		 'cword', 1, undef
	],
	[#Rule 36
		 'cword', 1, undef
	],
	[#Rule 37
		 'cword', 1, undef
	],
	[#Rule 38
		 'cword', 1, undef
	],
	[#Rule 39
		 'cword', 1, undef
	],
	[#Rule 40
		 'cword', 1, undef
	],
	[#Rule 41
		 'words', 2,
sub
#line 139 "lemon2yapp.yp"
{return "$_[1] $_[2]";}
	],
	[#Rule 42
		 'words', 1, undef
	],
	[#Rule 43
		 'word', 1, undef
	],
	[#Rule 44
		 'code_blk', 2, undef
	],
	[#Rule 45
		 'code_blk', 3, undef
	],
	[#Rule 46
		 'codes', 2, undef
	],
	[#Rule 47
		 'codes', 1, undef
	],
	[#Rule 48
		 'code', 1, undef
	],
	[#Rule 49
		 'code', 1, undef
	],
	[#Rule 50
		 'code', 1, undef
	],
	[#Rule 51
		 'code', 1, undef
	],
	[#Rule 52
		 'code', 1, undef
	],
	[#Rule 53
		 'code', 1, undef
	],
	[#Rule 54
		 'code', 1, undef
	],
	[#Rule 55
		 'code', 1, undef
	],
	[#Rule 56
		 'code', 1, undef
	]
],
                                  @_);
    bless($self,$class);
}

#line 165 "lemon2yapp.yp"


sub _error {
    die "\n\nSyntax error near '".$_[0]->YYCurval."'.\n";
}

sub _lexer {
  my($parser)=shift;

  for ($parser->YYData->{INPUT}) {
    s/^[\s]*//m;
    s/^(\/\/.*)$//m and return ('COMMENT', $1);
    s/^(\/[*])// and return ('COM_START', $1);
    s/^([*]\/)// and return ('COM_END', $1);
    s/^([{])// and return ('LCB', $1);
    s/^([}])// and return ('RCB', $1);
    s/^([(])// and return ('LP', $1);
    s/^([)])// and return ('RP', $1);
    s/^([\[])// and return ('LB', $1);
    s/^([\]])// and return ('RB', $1);
    s/^(::=)// and return ('EQ', $1);
    s/^([.])// and return ('DOT', $1);
    s/^(%ifdef)// and return ('IF', $1);
    s/^(%ifndef)// and return ('IF', $1);
    s/^(%endif)// and return ('FI', $1);
    s/^(%fallback)// and return ('FALLBACK', $1);
    s/^(%destructor)// and return ('DESTRUCTOR', $1);
    s/^(%left)// and return ('PREC', $1);
    s/^(%nonassoc)// and return ('PREC', $1);
    s/^(%right)// and return ('PREC', $1);
    s/^(%type)// and return ('TYPE', $1);
    s/^(%wildcard)// and return ('WILD', $1);
    s/^([^}{)(\]\[:.\s]+)// and return ('WORD', $1);
    s/^([\S]+)// and return ('WORD', $1);
    return ('', undef);




    #s/^(%name)// and return ('FALLBACK', $1);
    #s/^(%parse_accept)// and return ('FALLBACK', $1);
    #s/^(%parse_failure)// and return ('FALLBACK', $1);
    #s/^(%extra_argument)// and return ('', $1);
    #s/^(%include)// and return ('FALLBACK', $1);
    #s/^(%start)// and return ('FALLBACK', $1);
    #s/^(%stack_overflow)// and return ('FALLBACK', $1);
    #s/^(%stack_size)// and return ('FALLBACK', $1);
    #s/^(%start_symbol)// and return ('FALLBACK', $1);
    #s/^(%syntax_error)// and return ('FALLBACK', $1);
    #s/^(%token_destructor)// and return ('FALLBACK', $1);
    #s/^(%token_prefix)// and return ('FALLBACK', $1);
    #s/^(%token_type)// and return ('FALLBACK', $1);
  }
}

sub parse {
  my($self, $sql) = @_;
  $self->YYData->{INPUT} = $sql;
  $self->YYParse( yylex => \&_lexer, yyerror => \&_error, yydebug => 0x00);

  print "\n";
  foreach (@prec) {
    print "$_\n";
  }

  print <<'HEADER';

%{
  # add your global variables, subs, etc. here so they are available during
  # the parsing process.
%}

%%

HEADER

  foreach (@rules) {
    my @stuff = @{$rule{$_}};
    printf "%-15s : %s\n", $_, shift(@stuff);
    foreach my $i (@stuff) {
      printf "%-15s | %s\n", ' ', $i;
    }
    printf "%-15s ;\n\n", ' ';
  }
  
  print <<'FOOTER';

%%

#
# _error and _lexer methods are just examples. fill in your own stuff inside.
#

sub _error {
  my $self = shift;

  exists $self->YYData->{ERRMSG} and do {
    print $self->YYData->{ERRMSG};
    delete $self->YYData->{ERRMSG};
    return;
  };

  croak "Parse error near '".$self->YYCurval."':";
}

sub _lexer {
  my $self = shift;

  for ($self->YYData->{INPUT}) {
    s/^[\s]*//;
    s/^([0-9]*\.[0-9]+)//               and return ('FLOAT', $1);
    s/^([0-9]+)//                       and return ('INTEGER', $1);
    s/^([+])//                          and return ('PLUS', $1);
    s/^([-])//                          and return ('MINUS', $1);
    s/^([*])//                          and return ('STAR', $1);
    s/^([/])//                          and return ('SLASH', $1);
    s/^([%])//                          and return ('MOD', $1);
    s/^(.)//                            and return ('CHAR', $1);
    return ('', undef);
  }
}

sub parse {
  my($self, $input) = @_;
  $self->YYData->{INPUT} = $input;
  $self->YYParse( yylex => \&_lexer, yyerror => \&_error );
}

FOOTER
}

my $c = new lemon2yapp;
my @a = <STDIN>;
$c->parse(join('', @a));

1;
